<template>
	<view class="upload">
		<uni-nav-bar left-image="back" title="签到拍照" color="#000" fixed="true" status-bar="true" shadow="true"
			rightText="完成" @clickRight="menu()">
		</uni-nav-bar>
		<view class="list">
			<view class="item">
				<view class="image" v-if="storageImageList.length < 3">
					<image src="/static/my/tianjia.png" mode="" @click="upload()"></image>
				</view>
				<view class="uimage" v-for="(item,i) in storageImageList" :key="i">
					<image :src="item.full_filename" mode="" @click="previewImage(i)"></image>
					<view class="del" @click="del(i)"></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imageList: [],
				storageImageList: [], // 储存网络地址
			}
		},
		methods: {
			// 选择
			upload(e) {
				this.imageList = []
				this.$util.chooseImage(3 - this.imageList.length).then((res) => {
					uni.showLoading({
						title: '上传中'
					})
					if (this.imageList.length <= 3) {
						res.tempFilePaths.forEach((el) => {
							this.imageList.push(el)
						})
						res.tempFiles.forEach((el, index) => {
							let l = el.name.substring(el.name.lastIndexOf("."), el.name.length)
							this.$util.getAliyunOssSign(this.imageList[index], l).then((d) => {
								this.storageImageList.push(d.data)
								if (this.imageList.length == this.storageImageList.length) {
									uni.hideLoading()
								}
							})
						})
						setTimeout(() => {
							console.log(this.storageImageList)
						}, 300)
					}
				})
			},
			// 预览
			previewImage(i) {
				this.$util.previewImage(i, this.storageImageList)
			},
			// 删除
			del(i) {
				this.storageImageList.splice(i, 1)
			},

		},
	}
</script>

<style lang="scss">
	.upload {
		/deep/ .uni-nav-bar-right-text {
			background: #00A2EA;
			color: #fff;
			height: 56rpx;
			font-size: 30rpx;
			width: 123rpx;
			// padding: 0 34rpx;
			border-radius: 4rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}

	.item {
		display: flex;
		flex-wrap: wrap;
	}

	.item view {
		margin-right: 20rpx;
		margin-top: 10rpx;
	}

	.list {
		padding: 0 60rpx;
		margin-top: 71rpx;
		background: #fff;
	}

	.image {
		width: 204rpx;
		height: 195rpx;
		background: #F7F7F7;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 10rpx
	}

	.image image {
		width: 56rpx;
		height: 56rpx;
	}

	.uimage {
		position: relative;
	}

	.uimage image {
		width: 204rpx;
		height: 195rpx;
		border-radius: 10rpx
	}

	.footer {
		margin-top: 110rpx;
		display: flex;
		border-bottom: 1px solid #E5E5E5;
		padding-bottom: 20rpx;
	}

	.footer image {
		width: 29rpx;
		height: 34rpx;
		margin-right: 14rpx;
		margin-top: 5rpx;
	}

	.footer_right {
		display: flex;
		flex-direction: column;
	}

	.text {
		color: #999;
		font-size: 26rpx;
	}

	.view {
		font-size: 30rpx;
	}

	.del {
		width: 36rpx;
		height: 36rpx;
		border-radius: 50%;
		background-image: url(/static/project/checkWorkAttendance/shanchu.png);
		background-size: cover;
		position: absolute;
		right: -34rpx;
		top: -20rpx;
	}
</style>
